<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>通过Excel导入用户信息</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <!--<link rel="stylesheet" type="text/css" href="CSS/bootstrap-switch.min.css" />-->
    <!--<link rel="stylesheet" type="text/css" href="CSS/addContract.css" />-->
    <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>
    <script type="text/javascript" src="js/ajaxfileupload.js"></script>


</head>
<!--<script type="text/javascript">-->
<!--window.onload=function(){-->
<!--var btnAddUser=document.getElementById('submitExcel');-->
<!--btnAddUser.onclick=addUserByExcel()-->
<!--}-->
<!--</script>-->
<body>
<div class="form-group">
    <input id="userFile" type="file" name="file" size="15" accept=".xls" enctype="multipart/form-data" maxlength="100"/>
    <input type="button" id="submitExcel" onclick="addUserByExcel();" class="reg-btn" value="提交"/>
</div>
</body>
<script type="text/javascript">
    var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
    function addUserByExcel() {
        var filePath = $("#userFile").val();
        if(filePath==null || filePath==""){
            layer.msg('请选择要导入的用户文件，后缀为xls！', function(){
            });
        }else{
            uploadFile();
        }
    }
    function uploadFile() {
        $.ajaxFileUpload({
            url: hosturl+"/user/addExcel",
            secureuri: false,// 一般设置为false
            fileElementId: "userFile",// 文件上传表单的id <input type="file" id="fileUpload" name="file" />
            dataType: 'json',// 返回值类型 一般设置为json
            data: {},

            success: function (data) // 服务器成功响应处理函数
            {
                var index = parent.layer.getFrameIndex(window.name);
                if(data.status =="empty"){
                    layer.msg('请选择要导入的用户文件，后缀为xls！', function(){
                    });
                }else if(data.status == "ok"){
                    parent.$("#handle_status").val('OK');
                    parent.layer.close(index);
                }else if(data.status == "error"){
                    layer.msg(data.description, function(){
                    });
                }
            },
            error: function (xhr, type, errorThrown)// 服务器响应失败处理函数
            {
                console.log(type);
            }
        });
        return false;
    }
</script>
</html>